﻿namespace ClickNET.Web.UI
{
    using System;
    using System.Data;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;

    /// <summary>
    /// ClickNET Page base class
    /// </summary>
    public class Page : System.Web.UI.Page
    {
        private List<string> m_cssFiles;
        protected List<string> CssFiles
        {
            get
            {
                if (null == m_cssFiles)
                    m_cssFiles = new List<string>();

                return m_cssFiles;
            }
        }

        public bool ShowSearchBar { get; set; }

        protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.AddCssFile("clickdotnet.css");
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            Control searchPanel = null;
            Control header = null;

            if (null != base.Master)
            {
                header = base.Master.FindControl("c_header");
                searchPanel = base.Master.FindControl("c_searchPanel");
            }

            if (null != searchPanel)
                searchPanel.Visible = this.ShowSearchBar;

            // Find <head> and add stylesheet references
            if (null != header)
            {
                foreach (string cssFile in this.CssFiles)
                {
                    HtmlGenericControl linkTag = new HtmlGenericControl("link");
                    linkTag.Attributes.Add("rel", "stylesheet");
                    linkTag.Attributes.Add("type", "text/css");
                    linkTag.Attributes.Add("href", "css/" + cssFile);
                    header.Controls.Add(linkTag);
                }
            }
        }

        #region CSS Methods
        public void AddCssFile(string fileName)
        {
            this.CssFiles.Add(fileName);
        }
        #endregion
    }
}